package demoMod.invincibleOne.patches;

import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePrefixPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.dungeons.TheCity;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.helpers.EventHelper;
import com.megacrit.cardcrawl.random.Random;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.characters.InvincibleOne;
import demoMod.invincibleOne.events.Chat;

import java.util.ArrayList;

// >29层后的第一个二层事件一定是特殊事件
public class ChatEventPatch {
    @SpirePatch(
            clz = AbstractDungeon.class,
            method = "generateEvent",
            paramtypez = {Random.class}
    )
    public static class MustBeChatPatch {
        private static long temp;
        @SpireInsertPatch(rloc = 1)
        public static SpireReturn<AbstractEvent> Prefix(Random rng) {
            if (AbstractDungeon.player instanceof InvincibleOne) {
                // todo: 好像并不严谨。因为这会的SaveSlot和注册时候的SaveSlot不一定一样。
                if (AbstractDungeon.id.equals(TheCity.ID) && AbstractDungeon.floorNum >= 28 &&
                        !InvincibleOneMod.reskinUnlocked[CardCrawlGame.saveSlot])
                {
                    if (temp != Settings.seed) {
                        temp = Settings.seed;
                        return SpireReturn.Return(EventHelper.getEvent(Chat.ID));
                    }
                }
            }
            return SpireReturn.Continue();
        }

    }
}
